﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer.Management.Smo;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Common;
using System.Collections.Generic;
using System.Data.SqlClient;

/// <summary>
/// DBHelperSMO 的摘要描述
/// </summary>
namespace Chi.Lib.DBHelper
{
    public class DBHelperSMO
    {
        private static String _dbName = ConfigurationManager.AppSettings["DBName"];
        //private static ServerConnection conn = new ServerConnection(new SqlConnection(ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString));
        private static ServerConnection conn = new ServerConnection(DBHelper.DBHelperConnection.GetConnection());
        private static Microsoft.SqlServer.Management.Smo.Server _server;
        private static Database _db;

        private DBHelperSMO()
        { }

        public static Database GetDBInstance()
        {
            if (_db == null)
            {
                if (_server == null)
                {
                    _server = new Server(conn);
                }

                _db = _server.Databases[conn.DatabaseName];
            }

            return _db;
        }

        public static Server GetServerInstance()
        {
            if (_server == null)
            {
                _server = new Server(conn);
            }
            return _server;
        }
    }
}